package com.cw.reduce.filter;

import java.util.Vector;

import com.cw.util.Digit;

public class PrimeFilter implements IFilter {
	private int which = -1;

	public PrimeFilter(int which) {
		this.which = which;
	}

	/**
	 * startFilter
	 * 
	 * @param condition
	 *            Vector
	 * @param target
	 *            Vector
	 * @return Vector
	 * @todo Implement this cp.gui.reduce.filter.IFilter method
	 */
	public Vector startFilter(Vector condition, Vector<Integer> target) {
		Vector result = new Vector();
		String condi = (String) condition.elementAt(0);

		for (int i = 0; i < target.size(); i++) {
			int value = target.elementAt(i);
			int tempVal = value;
			if (which == 1) {
				String temp = "000" + String.valueOf(value);
				String str = String.valueOf(temp.charAt(temp.length() - 1))
						+ String.valueOf(temp.charAt(temp.length() - 2))
						+ String.valueOf(temp.charAt(temp.length() - 3));
				tempVal = Integer.valueOf(str);
			}
			if (condi.equals("prime") && Digit.prime(tempVal)) {
				result.add(value);
			}
			if (condi.equals("non-prime") && !Digit.prime(tempVal)) {
				result.add(value);
			}
		}
		return result;
	}

}
